package com.example.wearing.tools;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.wearing.R;
import com.example.wearing.javabean.Reply;

import java.util.ArrayList;

public class ReplyAdapter extends ArrayAdapter {
    private static final String TAG = "ReplyAdapter";
    public ReplyAdapter(Context context,
                       int resource,
                       ArrayList<Reply> list) {
        super(context, resource, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView = convertView;
        if (itemView == null) {
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.reply_list,
                    parent,
                    false);
        }

        Reply reply = (Reply) getItem(position);
        TextView replyContent = (TextView) itemView.findViewById(R.id.replyContent);
        TextView replyUsername = (TextView) itemView.findViewById(R.id.replyUserName);
        TextView replyTime = (TextView) itemView.findViewById(R.id.replyTime);
        ImageView userimg = (ImageView) itemView.findViewById(R.id.userImg);


        replyContent.setText(reply.getR_content());
        replyUsername.setText(reply.getR_user());
        replyTime.setText(reply.getR_time());

        String userimgStr = reply.getR_userimg();
        Bitmap userimgBitmap = ImageUtil.base64ToImage(userimgStr);
        userimg.setImageBitmap(userimgBitmap);

        return itemView;
    }

}
